﻿CREATE TRIGGER [dbo].[tr_StateParameter_Enum]
ON [dbo].[ts_StateParameter]
FOR INSERT,UPDATE,DELETE
AS 

IF UPDATE(Name)BEGIN
	DECLARE @SQL nvarchar(4000)
	SELECT @SQL = admin.MakeEnumObjectNameSQL(admin.MakeStateParamEnumObjectName(ID),
																						dbo.fn_TriggerTable(object_name(@@PROCID)),
																						ID,
																						object_id(admin.MakeStateParamEnumObjectName(ID)))
	FROM inserted
	PRINT(@SQL)
	EXEC(@SQL)
	RETURN
END

IF EXISTS(SELECT * FROM inserted) RETURN

DECLARE @ObjectName sysname SELECT @ObjectName = admin.MakeStateEnumObjectName(ID) FROM deleted
EXEC dbo._DropObject @ObjectName
